package com.yunhe.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.yunhe.bean.page;
import com.yunhe.test.test;

/**
 * Servlet implementation class ShowMessage_Servlet
 */
@WebServlet("/ShowMessage_Servlet")
public class ShowMessage_Servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ShowMessage_Servlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		test test=new test();
		//设置默认页面数为1
		int defaultPage=1;
		//判断是否是首次进入该页面,如果不是则改变默认页面数
		if(request.getParameter("currentPage")!=null){
			defaultPage=Integer.parseInt(request.getParameter("currentPage"));
		}
		//设置一个page对象
		page pg=new page();
		pg.setCurrentPage(defaultPage);
		int countComment=test.countm();
		pg.setTotalNews(countComment);
		int totalPage=pg.getTotalPage();
		//引用bus对象及方法		
		Map map=new HashMap();
		ArrayList commentList=new ArrayList();
		commentList=(ArrayList) test.showm(pg);
		map.put("commentList",commentList);
		map.put("totalPage", totalPage);
		map.put("page", pg);
		//传递map到前端
		request.setAttribute("map",map);
		//页面转向到前端
		request.getRequestDispatcher("manage/guestbook.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
